package guoanmaker.provider.business.controller;

import java.io.InputStream;

import io.swagger.annotations.ApiOperation;
import guoanmaker.provider.business.model.PersonalInvestorDisplay;
import guoanmaker.provider.business.model.PersonalPlatform;
import guoanmaker.provider.business.service.PersonalInvestorDisplayServiceinterface;
import guoanmaker.provider.helper.common.AjaxJson;
import guoanmaker.provider.helper.common.abstractobj.ApiController;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping(ApiController.COMMODITY_URL)
public class PersonalInvestorDisplayController {
	
	@Autowired
	private PersonalInvestorDisplayServiceinterface  personalInvestorDisplayService;
	
	
	@ApiOperation(value="录入投资人信息",notes="录入投资人信息")
	@PostMapping("/insertPersonalInvestorDisplay")
	public AjaxJson insertPersonalInvestorDisplay(@RequestParam MultipartFile dataFile){
		AjaxJson ajaxJson=new AjaxJson();
		try (InputStream in = dataFile.getInputStream(); Workbook wb = WorkbookFactory.create(in);) {
			personalInvestorDisplayService.insertPersonalPlatform(wb);
		     ajaxJson.setSuccess(true).setStatus(200).setData("录入成功");
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("录入失败");
		}
		return ajaxJson;
		
	}
	
	@ApiOperation(value="分页查询投资人信息",notes="分页查询投资人信息")
	@PostMapping("/selectPersonalInvestorDisplay")
	public AjaxJson selectPersonalInvestorDisplay(@RequestParam(value = "page", defaultValue = "0") Integer page,
            @RequestParam(value = "size", defaultValue = "10") Integer size) {
		AjaxJson ajaxJson=new AjaxJson();	
		try {
				ajaxJson.setSuccess(true).setStatus(200).setData(personalInvestorDisplayService.selectPersonalInvestorDisplay(page,size));
			} catch (Exception e) {
				e.printStackTrace();
				ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
			}
		
		  return ajaxJson;
		
	}
	
	
	@ApiOperation(value="新增/修改投资人信息" ,notes="新增/修改投资人信息")
	@PostMapping("/addorUpdatePersonalInvestorDisplay")
	public AjaxJson  addorUpdatePersonalInvestorDisplay(@RequestBody PersonalInvestorDisplay personalInvestorDisplay){
		AjaxJson ajaxJson=new AjaxJson();
		ajaxJson.setSuccess(true).setStatus(200).setData(personalInvestorDisplayService.addorUpdatePersonalInvestorDisplay(personalInvestorDisplay));
		return	ajaxJson;
	}
	
	@ApiOperation(value="删除投资人信息" ,notes="删除投资人信息")
	@PostMapping("/deletePersonalInvestorDisplay")
	public AjaxJson deletePersonalInvestorDisplay(String id){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			personalInvestorDisplayService.deletePersonalInvestorDisplay(id);
			ajaxJson.setSuccess(true).setStatus(200).setData("删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("删除失败");
		}
		return ajaxJson;
	
	}
	
	
	@ApiOperation(value="根据id查询投资人详情信息",notes="查询投资人详情信息")
	@PostMapping("/selectOnePersonalInvestorDisplay")
	public AjaxJson selectOnePersonalInvestorDisplay(String id) {
		AjaxJson ajaxJson=new AjaxJson();
			try {
				ajaxJson.setSuccess(true).setStatus(200).setData(personalInvestorDisplayService.selectOnePersonalInvestorDisplay(id));
			} catch (Exception e) {
				e.printStackTrace();
				ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
			}
		
		  return ajaxJson;
		
	}
	
}
